<?php
include_once ("mysqllib.php");

class slide {

	private $idSlide;
	private $idVideo;
	private $time;
	private $type;
	private $filePath;

	public function addSlide($idVideo, $time, $type, $filePath) {
		//connect to the database
		$db = new mysqllib();

		$query = "INSERT INTO Slide (idVideo,time, type, filePath) VALUES ('$idVideo','$time', '$type', '$filePath')";
		$result = mysql_query($query);

		//If the query worked
		if ($result) {
			//Get the idSlide
			$query2 = "SELECT idSlide FROM Slide where 
					  idVideo='$idVideo' AND time='$time' AND type='$type' AND filePath='$filePath'";

			$result2 = mysql_query($query2);
			$data2 = mysql_fetch_array($result2);
			$idSlide = $data2['idSlide'];

			//Set the slide to the added one
			$this -> idSlide = $idSlide;
			$this -> idVideo = $idVideo;
			$this -> time = $time;
			$this -> type = $type;
			$this -> filePath = $filePath;

		}
	}

	public function setSlides($idSlide, $idVideo, $time, $type, $filePath) {
		$this -> idSlide = $idSlide;
		$this -> idVideo = $idVideo;
		$this -> time = $time;
		$this -> type = $type;
		$this -> filePath = $filePath;
	}

	public function getSlideById($id) {
		//connect to the database
		$db = new mysqllib();

		$query = "SELECT * FROM Slide WHERE idSlide='$id'";

		$result = mysql_query($query);
		$data = mysql_fetch_array($result);

		//Fill the current object with the fetched slide's informations.
		$this -> idSlide = $data['idSlide'];
		$this -> idVideo = $data['idVideo'];
		$this -> time = $data['time'];
		$this -> type = $data['type'];
		$this -> filePath = $data['filePath'];

	}
	
	public function displaySlidePin($duration, $id){
		echo '<img id="slide' . $id . '" data-timeslide="' . $this -> time . '" onclick="moveVideoTo(' . $this->time . ')" src="img/pinBlue.png" width = 12 height = 20 style="position : absolute; left:';
		$pos = (($this -> time / $duration) + (6/640)) * 100;
		echo "$pos%";
		echo ';">';
	}

}
?>